package com.library.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;

@Data
public class BookDTO implements Serializable {

    // 书名
    @NotBlank(message = "书名不能为空")
    private String title;
    // 作者
    @NotBlank(message = "作者不能为空")
    private String author;
    //ISBN
    @NotBlank(message = "ISBN不能为空")
    @Pattern(regexp = "^\\d{10}$|^\\d{13}$", message = "ISBN格式不正确（必须为10或13位数字）")
    private String isbn;
    //出版时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    //@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    @NotNull(message = "出版日期不能为空")
    @PastOrPresent(message = "出版日期不能是未来日期")
    private LocalDate publishDate;
    // 书籍分类id
    private Long categoryId;
    //价格
    @NotNull(message = "价格不能为空")
    @DecimalMin(value = "0.0", inclusive = false, message = "价格必须大于0")
    @Digits(integer = 5, fraction = 2, message = "价格格式不正确（最多5位整数和2位小数）")
    private BigDecimal price;
    //书籍封面
    private String cover;
    //书籍描述
    private String description;
    //书籍库存
    private Integer stock;



}
